Skip to content

feat(wasm-dot): change encodeSs58/validateAddress to accept number prefix#204

Closed
bitgo-ai-agent-dev[bot] wants to merge 1 commit intomasterfrom
BTC-3127.wasm-dot-encode-ss58-number-prefix
Closed

feat(wasm-dot): change encodeSs58/validateAddress to accept number prefix#204
bitgo-ai-agent-dev[bot] wants to merge 1 commit intomasterfrom
BTC-3127.wasm-dot-encode-ss58-number-prefix

Conversation

@bitgo-ai-agent-dev
Copy link

Summary

  • Change encodeSs58(publicKey, format: AddressFormat)encodeSs58(publicKey, prefix: number) in @bitgo/wasm-dot
  • Change validateAddress(address, format?: AddressFormat)validateAddress(address, prefix?: number) for consistency
  • Remove the AddressFormat import from address.ts (no longer used there)
  • The AddressFormat enum remains exported from types.ts as named constants for callers

Why

The underlying Rust WASM binding (AddressNamespace.encodeSs58) already accepts a u16 prefix. The TypeScript wrapper was unnecessarily constraining callers to use the AddressFormat enum, requiring an as unknown as AddressFormat cast when bridging from sdk-core's DotAddressFormat enum.

Since AddressFormat is a numeric enum (Polkadot=0, Kusama=2, Substrate=42), existing callers that pass AddressFormat.Polkadot etc. continue to compile without any changes — numeric enum values are assignable to number.

Backward Compatibility

No breaking change. Callers using AddressFormat.Polkadot / AddressFormat.Substrate constants continue to work as-is; TypeScript numeric enums assign to number without a cast.

Follow-up

After this ships, bgms/dot.ts can drop toWasmAddressFormat and the AddressFormat import, passing addressFormat (a DotAddressFormat number) directly to encodeSs58. See T1-57.

Test plan

  • Existing tests in test/address.ts use AddressFormat.Substrate / AddressFormat.Polkadot as named constants and still compile and pass without changes
  • TypeScript compilation succeeds (no noUnusedLocals errors — AddressFormat was removed from address.ts where it was used, and remains in types.ts and tests)

Ticket: T1-57
🤖 Generated with Claude Code

…r prefix

Replace AddressFormat enum parameter with plain number in encodeSs58 and
validateAddress. The AddressFormat enum remains exported as a named-constants
convenience; since its members are numeric (Polkadot=0, Kusama=2, Substrate=42),
existing callers passing AddressFormat.Polkadot etc. continue to compile without
change — numeric enum values are assignable to number.

This eliminates the need for callers to import AddressFormat just to satisfy the
type, and avoids as-unknown-as casts when bridging to sdk-core's DotAddressFormat.
Mirrors the pattern used by wasm-utxo, which accepts plain primitives.

Ticket: T1-57
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bitgo-ai-agent-dev bitgo-ai-agent-dev bot requested a review from a team as a code owner March 10, 2026 22:29
@bitgo-ai-agent-dev
Copy link
Author

Closing in favour of PR #203 (btc-3117/wasm-dot-address-format-union-type), which takes a better approach: replacing the enum with a type AddressFormat = 0 | 2 | 42 union + const AddressFormat object. That keeps callers type-safe (no arbitrary number accepted) while still eliminating the as unknown as cast in bgms, which was the goal. The as const satisfies Record<string, AddressFormat> in #203 is correct — it narrows the const object's values to literal types while validating them against the union.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant